package com.dementors.ui.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.dementors.R;
import com.dementors.base.BaseActivity;
import com.dementors.view.MyImageView;
import com.dementors.view.MyImageView.OnLloutCheckedListener;
import com.dementors.view.MyTitleView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/12/5 0005.
 */
public class LoginActivity extends BaseActivity implements MyTitleView.OnTitlecheckedListener, TextWatcher {
    private int[] res={R.drawable.img_login_weixin,R.drawable.img_login_qq,R.drawable.img_login_taobao,R.drawable.img_login_weibo};
    private String[] text={"微信","QQ","淘宝","新浪微博"};
    private ArrayList<MyImageView> mivs=new ArrayList<>();
    private MyImageView mivLogin1,mivLogin2,mivLogin3,mivLogin4;
    private MyTitleView mtv;
    private ImageView ivClean;
    private EditText etUser,etPass;
    private Button btnin;


    @Override
    protected int provideContentViewId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        initLoginview();//初始化合作方登录处4个控件
        initTitleview();//初始化标题控件
        initUserView();//初始化账号控件
        initBtnIn();//初始化立即登录按钮


    }

    private void initBtnIn() {
        btnin= (Button) findViewById(R.id.btn_login_in);
    }

    private void initUserView() {
        ivClean= (ImageView) findViewById(R.id.iv_clean);
        etUser= (EditText) findViewById(R.id.et_user);
        etPass= (EditText) findViewById(R.id.et_password);
    }

    private void initTitleview() {
        mtv= (MyTitleView) findViewById(R.id.mtv_login);
    }

    private void initLoginview() {
        mivLogin1= (MyImageView) findViewById(R.id.miv_login1);
        mivLogin2= (MyImageView) findViewById(R.id.miv_login2);
        mivLogin3= (MyImageView) findViewById(R.id.miv_login3);
        mivLogin4= (MyImageView) findViewById(R.id.miv_login4);
        mivs.add(mivLogin1);
        mivs.add(mivLogin2);
        mivs.add(mivLogin3);
        mivs.add(mivLogin4);
        for (int i=0;i< mivs.size();i++){
            mivs.get(i).setImageView(res[i]);
            mivs.get(i).setText(text[i]);
            mivs.get(i).setTag(i);
        }
    }

    @Override
    protected void setListener() {
        mtv.setOnTitlecheckedListener(this);
        etUser.addTextChangedListener(this);
        ivClean.setOnClickListener(this);
        btnin.setOnClickListener(this);
        etPass.addTextChangedListener(this);
        mivLogin1.setOnLloutCheckedListener(new OnLloutCheckedListener() {
            @Override
            public void setOnLloutCheckedListener() {

            }
        });
        mivLogin2.setOnLloutCheckedListener(new OnLloutCheckedListener() {
            @Override
            public void setOnLloutCheckedListener() {

            }
        });
        mivLogin3.setOnLloutCheckedListener(new OnLloutCheckedListener() {
            @Override
            public void setOnLloutCheckedListener() {

            }
        });
        mivLogin4.setOnLloutCheckedListener(new OnLloutCheckedListener() {

            @Override
            public void setOnLloutCheckedListener() {

            }
        });

    }


    @Override
    protected void initData() {
//        UMSocialService.doOauthVerify(this , SHARE_MEDIA platform , UMAuthListener listener)
    }

    @Override
    protected void getIntentData(Bundle saveInstance) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_clean:
                etUser.setText("");
                ivClean.setVisibility(View.INVISIBLE);
                break;
            case R.id.btn_login_in:
//                Log.i("oye","我运行到这边了1");
                if (etUser.getText()==null|| etUser.getText().toString().equals("")){
                    Toast.makeText(this,"账号不能为空",Toast.LENGTH_SHORT).show();
//                Log.i("oye", "我运行到这边了2");
                }else if (etPass.getText()==null||etPass.getText().toString().equals("")){
                    Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    /**
     * 返回按钮的监听
     */
    @Override
    public void setOnTitleBackListener() {
        finish();
    }

    /**
     * 跳转到注册页面的监听
     */
    @Override
    public void setOnTitleToListener() {

    }

    /**
     * 账号输入前
     * @param s
     * @param start
     * @param count
     * @param after
     */
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    /**
     * 账号输入时
     * @param s
     * @param start
     * @param before
     * @param count
     */
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        ivClean.setVisibility(View.VISIBLE);
    }

    /**
     * 账号输入后
     * @param s
     */
    @Override
    public void afterTextChanged(Editable s) {

    }




}
